//入口文件
//1. 导入相关的模块
const express=require('express');
const path=require('path');  //将public目录、template目录设置成动态的绝对路径    __dirname内置常量
const bodyParser=require('body-parser');
const cookieParser=require('cookie-parser');

//2.创建应用实例
const app=express();

//3.设置模板引擎
// console.log(__dirname);
// console.log(path.join(__dirname,'templates'))
app.set('views',path.join(__dirname,'templates'));
app.set('view engine','ejs');

//4.应用中间件
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cookieParser());

//5.加载静态目录public
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname,'public')));

//8.导入moment插件
const moment=require('moment');
app.locals.moment=moment;

//7.调用业务模块
const login=require('./routes/login');
const home=require('./routes/home');
const logout=require('./routes/logout');
const homeTeach=require('./routes/home_teach');
const checkpwd=require('./routes/checkpwd');
const selmeans=require('./routes/sel_means');
const addmeans=require('./routes/add_means');
const selscores=require('./routes/sel_scores');
const addscores=require('./routes/add_scores');
const meansupd=require('./routes/means_upd');

//设置访问地址
app.use('/',login);
app.use('/home',home);
app.use('/logout',logout);
app.use('/home_teach',homeTeach);
app.use('/checkpwd',checkpwd);
app.use('/sel_means',selmeans);
app.use('/add_means',addmeans);
app.use('/sel_scores',selscores);
app.use('/add_scores',addscores);
app.use('/means_upd',meansupd);


//6.开启监听
app.listen(8080,()=>{
    console.log('项目启动成功，打开链接：http://localhost:8080');
})